package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseCatalogCreateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseCatalogDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseCatalogUpdateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminGetCourseCatalogByCourseIdRespVO;
import com.hsjk.szwj.module.train.service.ICourseCatalogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/09/25 16:11
 **/
@Tag(name = "后台管理端 - 培训课程目录相关接口")
@RestController
@RequestMapping("/train/course/catalog")
@Validated
public class AdminCourseCatalogController {
    @Resource
    ICourseCatalogService courseCatalogService;

    @GetMapping("/list-by-course-id")
    @Operation(summary = "根据课程id获取课程目录列表")
    @PreAuthorize("@ss.hasPermission('train:course-catalog:query')")
    public CommonResult<List<AdminGetCourseCatalogByCourseIdRespVO>> listCourseCatalogByCourseId(
            @RequestParam Long courseId) {
        return success(courseCatalogService.listCourseCatalogByCourseId(courseId));
    }

    @GetMapping("/get-course-catalog-detail")
    @Operation(summary = "获取课程目录详情")
    @PreAuthorize("@ss.hasPermission('train:course-catalog:query')")
    public CommonResult<AdminCourseCatalogDetailRespVO> getCourseCatalogDetail(@RequestParam Long id) {
        return success(courseCatalogService.getCourseCatalogDetail(id));
    }

    @PostMapping("/create")
    @Operation(summary = "创建课程目录")
    @PreAuthorize("@ss.hasPermission('train:course-catalog:create')")
    public CommonResult<Boolean> createCourseCatalog(@RequestBody @Valid AdminCourseCatalogCreateReqVO reqVO) {
        return success(courseCatalogService.createCourseCatalog(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新课程目录")
    @PreAuthorize("@ss.hasPermission('train:course-catalog:update')")
    public CommonResult<Boolean> updateCourseCatalog(@RequestBody @Valid AdminCourseCatalogUpdateReqVO reqVO) {
        return success(courseCatalogService.updateCourseCatalog(reqVO));
    }

    @PostMapping("/delete")
    @Operation(summary = "删除课程目录")
    @PreAuthorize("@ss.hasPermission('train:course-catalog:delete')")
    public CommonResult<Boolean> deleteCourseCatalog(@RequestParam Long id) {
        return success(courseCatalogService.deleteCourseCatalog(id));
    }
}
